package cn.tedu;

import com.sun.media.jfxmediaimpl.HostUtils;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import javax.print.DocFlavor;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/*用于练习综合案例---成员变量 局部变量 封装 继承 多态 抽象 静态属性/方法的调用 重写重载 接口  字节 字符  集合*/
public class Variable {

    public static void main(String[] args) {
//        new ioo().lll().li();

        fan();

        zjl();
        zfl();

        opp o= new ioo();

        System.out.println(o.WUWUWU);
        o.setAge(15);
        System.out.println(o.getAge());
        o.poo();
        o.poo(5);
        o.poo("ufg");
        o.opp("gdsfuy",54,5);
        o.iii();
        ppp p=new ioo();
        ioo h = new ioo();
        h.zzz();
        p.dgfsg();
        p.ooo();


    }

    private static void fan() {//Collection  泛型
        Collection<Character> w = new ArrayList();
        w.add('1');
        w.add('2');
        w.add('3');
        System.out.println(w);
        System.out.println(w.toArray());
        System.out.println(w.contains(5));

    }

    private static void zfl() {
        Reader in = null;
        Writer out = null;
        try {
            in = new FileReader(new File("D:\\ready\\1.txt"));
            in =new BufferedReader(new FileReader(new File("D:\\ready\\1.txt")));
            int  s;
            while((s=in.read())!=-1){
                System.out.println(s);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            out = new FileWriter("D:\\ready\\3.txt");
            out = new BufferedWriter(new FileWriter("D:\\ready\\3.txt"));
            out.write(564685);
            out.write(564685);
            out.write(564685);
            out.write(564685);
            out.write(564685);
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    private static void zjl() {
        InputStream in= null;
        OutputStream out= null;
        try {
//            in = new FileInputStream(new File("D:\\ready\\1.txt"));
            in = new BufferedInputStream(new FileInputStream("D:\\ready\\1.txt"));
            int b;
            while((b=in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
//            out= new FileOutputStream(new File("D:\\ready\\1.txt"));
            out = new BufferedOutputStream(new FileOutputStream("D"));
            out.write(45);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
interface ppp{
    int a =9;
    void dgfsg();
    void ooo ();
}
abstract class opp implements ppp{
    static{
        System.out.println("静态代码块,类里方法外,随着当前类加载而加载,只加载一次,便释放出去");
    }
    {
        System.out.println("构造代码块,类里方法外,随着当前类加载而加载,每一次都会加载,当前类消失它便消失");
    }
    static String WUWUWU;

    public void iii(){
        {
            System.out.println("局部代码块,方法里,随着方法加载而加载,方法消失便随之释放");
        }
        String a = "abc";
        String c = "ABC";
        char[] b = {'a','b','c'};
        System.out.println(b);
        System.out.println(a.hashCode()+"哈希码值");
        System.out.println(b.hashCode()+"哈希码值");
        System.out.println(a.equals(b));
        System.out.println(Arrays.toString(b)+"返回数组类型");
        System.out.println(a.toUpperCase()+"全大写");
        System.out.println(c.toLowerCase()+"全小写");
        System.out.println(a.indexOf("a")+"是否已字母a开头");
        System.out.println(a.lastIndexOf("c")+"是否已字母c结尾");
        System.out.println(a.startsWith("b")+"第一次出现字母b的下标");
        System.out.println(a.endsWith("c")+"最后一次出现字母c的下标");

        String aa = "   ffff  ff f df d  ";
        System.out.println(aa.trim()+"去除首尾空格");
        System.out.println(a.concat(aa)+"拼接");

        String bb = "ababababababababa";
        System.out.println(Arrays.toString(bb.split("b"))+"字母b为分隔符");

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

     private String name;
     private int age;
     private int id;


    public  void opp(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    public abstract void opp();

    public void poo(String i){
        String id="4156456";
        String name="高度";
        System.out.println(id);
        System.out.println(age);
        System.out.println(this.id);
        System.out.println(name);
        System.out.println(this.name);
        System.out.println(a);
    }
    public void poo(){
        String id="46456";
        String name="度";
        System.out.println(id);
        System.out.println(age);
        System.out.println(this.id);
        System.out.println(name);
        System.out.println(this.name);
    }
    public void poo(int a){
        String id="41568789";
        String name="dfui";
        System.out.println(id);
        System.out.println(age);
        System.out.println(this.id);
        System.out.println(name);
        System.out.println(this.name);
    }
}
class ioo extends opp implements ppp{
    String name;
    @Override
    public  void opp(){
        String ig =null;
        System.out.println(ig);
        System.out.println("jgfd");
    }

    @Override
    public void dgfsg() {
        System.out.println("kfgkohg");
    }

    @Override
    public void ooo() {
        super.poo(12);
        this.dgfsg();
        System.out.println(this.name);

        String name = null;//局部变量
        System.out.println(name);
        System.out.println("knmn");
        System.out.println(super.getName());
    }
    public  void zzz(){
        lll l2 = new lll();
        l2.l1();
    }
    private class lll{
        public void l1(){
            File file = new File("D:\\ready\\1.txt");

            System.out.println(file.isFile());
            System.out.println(file.getName());
            System.out.println(file.getParent());
            System.out.println(file.length());
            System.out.println(file.mkdir());

        }
    }
}

